package com.itheima.Test;

import java.util.Scanner;

public class Demo5 {
    public static void main(String[] args) {
        //1.定义一个数组，用动态初始化完成数组元素的初始化，长度为6
        int[] arr =  new int[6];
        //2.键盘录入评委分数
        Scanner sc = new Scanner(System.in);
        //3.由于是6个评委打分，所以，接收评委分数的操作，用循环来实现
        for (int i = 0; i < arr.length; i++) {
            System.out.println("请输入第"+(i+1)+ "个分数");
            int score = sc.nextInt();
            if(score >= 0 && score <=100){
                //合法分值
                arr[i] = score;
            }else{
                //非法分值
                System.out.println("您的输入有误，请重新输入");
                i--;
            }
        }
        //4.求出数组最大值
        int max = arr[0];
        for (int i = 1; i < arr.length; i++) {
            if(arr[i] > max){
                max = arr[i];
            }
        }
        //5.求出数组最小值
        int min = arr[0];
        for (int i = 1; i < arr.length; i++) {

            if(arr[i] < min){
                min = arr[i];
            }
        }
        //6.求出数组总和
        int sum = 0;
        for (int i = 0; i < arr.length; i++) {
            sum += arr[i];
        }
        int avg = (sum - max - min) / 4;
        System.out.println("该选手的平均分为" + avg);
    }
}
